Repository navigation
[KYUUBI #7590][SPARK] Stop waiting after SparkContext shutdown - #7797
dajiaohuang wants to merge 4 commits into
Conversation
|
Hello @dajiaohuang, |
|
can you change it to the #7680 version? I feel that is much readable? |
|
Thanks for the suggestion. I simplified the wait helper to use the one-second timed-latch loop from #7680, with the stopped-context check and warning. I intentionally exit the wait rather than call The targeted |
| private val namespace = "n" * 63 | ||
| private val podUid = "u" * 36 | ||
|
|
||
| test("[KYUUBI #7590] stop waiting when SparkContext has stopped") { |
There was a problem hiding this comment.
it's overkill to add such an ut, remove it and inline the def waitForEngineTermination
There was a problem hiding this comment.
Done in commit 9ace3f8. I removed the unit test and helper, and inlined the timed wait in main; when SparkContext stops, the method returns through the existing finally cleanup. git diff --check passed. Maven tests were not rerun because of the shared Zinc-cache restriction.
pan3793
left a comment
There was a problem hiding this comment.
Thanks for the fix. A few comments:
- Throw
KyuubiExceptioninstead ofreturnwhen SparkContext is stopped, see inline. - Revert the unrelated blank-line removal.
- Please update the PR description to match the final change: the "How was this patch tested?" section mentions a regression test that is no longer in the diff, and the "without calling
engine.stop()again" wording will be stale after (1).
| if (spark.sparkContext.isStopped) { | ||
| // stop() may already be running, so exit the wait instead of calling it again. | ||
| warn("SparkContext has been stopped, breaking main thread wait") | ||
| return |
There was a problem hiding this comment.
Throw a KyuubiException here instead of returning. If SparkContext stops before the latch is released, the engine is terminating abnormally. A normal return makes YARN report the app as SUCCEEDED and spark-submit exit 0. Throwing also reuses the catch below: it calls engine.stop() (a no-op if a stop is already in flight, because of shutdown.compareAndSet), posts the end EngineEvent with diagnostics, and logs at error level.
while (!countDownLatch.await(1, TimeUnit.SECONDS)) {
if (spark.sparkContext.isStopped) {
throw new KyuubiException(
"SparkContext stopped before SparkSQLEngine, terminating the engine main thread")
}
}Please also update the comment above the loop to match.
There was a problem hiding this comment.
Implemented in 17c5766: if SparkContext stops before the latch is released, the main thread now throws KyuubiException and uses the existing engine error path to stop/report abnormal termination. I updated the loop comment as well. Tests were not rerun because the protected shared Zinc-cache restriction remains; the PR description now states that limit.
| private lazy val user = currentUser | ||
|
|
||
| private val countDownLatch = new CountDownLatch(1) | ||
|
|
There was a problem hiding this comment.
Unrelated change, please revert.
There was a problem hiding this comment.
Reverted the unrelated blank-line removal in SparkSQLEngine.scala.
Fixes #7590. ### Why are the changes needed? When SparkContext stops before engine shutdown reaches `stopServer()`, the latch in `SparkSQLEngine.main` may never be released. The main thread polls the latch and checks SparkContext; if it is stopped first, the code now throws `KyuubiException` through the existing engine error path. That path records the abnormal termination and diagnostics instead of returning normally (which could make YARN report the application as succeeded). Earlier PRs #7592 and #7680 are closed and unmerged. ### How was this patch tested? - `git diff --check` passed for this review follow-up. - Maven/Spotless and the Spark test suite were not rerun for this revision because the protected shared Zinc-cache incident prohibits Maven reruns. The earlier 3/3 `SparkSQLEngineSuite` run was on commit `e24adad`, before this follow-up, and does not validate the current diff. ### Was this patch assisted by generative AI tooling? Assisted-by: Pi worker dev-w11stew-c1-4w (openai-codex/gpt-6-luna). Closes #7797 from dajiaohuang/kyuubi-7590-spark-context-stop. Closes #7590 17c5766 [dajiaohuang] Report abnormal SparkContext termination 9ace3f8 [dajiaohuang] Inline SparkContext termination wait e24adad [dajiaohuang] Simplify SparkContext termination wait bfb8d04 [dajiaohuang] [KYUUBI #7590][SPARK] Stop waiting after SparkContext shutdown Authored-by: Wu Shuwen <mikewushuwen@outlook.com> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit d953184) Signed-off-by: Cheng Pan <chengpan@apache.org>
Fixes #7590. ### Why are the changes needed? When SparkContext stops before engine shutdown reaches `stopServer()`, the latch in `SparkSQLEngine.main` may never be released. The main thread polls the latch and checks SparkContext; if it is stopped first, the code now throws `KyuubiException` through the existing engine error path. That path records the abnormal termination and diagnostics instead of returning normally (which could make YARN report the application as succeeded). Earlier PRs #7592 and #7680 are closed and unmerged. ### How was this patch tested? - `git diff --check` passed for this review follow-up. - Maven/Spotless and the Spark test suite were not rerun for this revision because the protected shared Zinc-cache incident prohibits Maven reruns. The earlier 3/3 `SparkSQLEngineSuite` run was on commit `e24adad`, before this follow-up, and does not validate the current diff. ### Was this patch assisted by generative AI tooling? Assisted-by: Pi worker dev-w11stew-c1-4w (openai-codex/gpt-6-luna). Closes #7797 from dajiaohuang/kyuubi-7590-spark-context-stop. Closes #7590 17c5766 [dajiaohuang] Report abnormal SparkContext termination 9ace3f8 [dajiaohuang] Inline SparkContext termination wait e24adad [dajiaohuang] Simplify SparkContext termination wait bfb8d04 [dajiaohuang] [KYUUBI #7590][SPARK] Stop waiting after SparkContext shutdown Authored-by: Wu Shuwen <mikewushuwen@outlook.com> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit d953184) Signed-off-by: Cheng Pan <chengpan@apache.org>
Fixes #7590. ### Why are the changes needed? When SparkContext stops before engine shutdown reaches `stopServer()`, the latch in `SparkSQLEngine.main` may never be released. The main thread polls the latch and checks SparkContext; if it is stopped first, the code now throws `KyuubiException` through the existing engine error path. That path records the abnormal termination and diagnostics instead of returning normally (which could make YARN report the application as succeeded). Earlier PRs #7592 and #7680 are closed and unmerged. ### How was this patch tested? - `git diff --check` passed for this review follow-up. - Maven/Spotless and the Spark test suite were not rerun for this revision because the protected shared Zinc-cache incident prohibits Maven reruns. The earlier 3/3 `SparkSQLEngineSuite` run was on commit `e24adad`, before this follow-up, and does not validate the current diff. ### Was this patch assisted by generative AI tooling? Assisted-by: Pi worker dev-w11stew-c1-4w (openai-codex/gpt-6-luna). Closes #7797 from dajiaohuang/kyuubi-7590-spark-context-stop. Closes #7590 17c5766 [dajiaohuang] Report abnormal SparkContext termination 9ace3f8 [dajiaohuang] Inline SparkContext termination wait e24adad [dajiaohuang] Simplify SparkContext termination wait bfb8d04 [dajiaohuang] [KYUUBI #7590][SPARK] Stop waiting after SparkContext shutdown Authored-by: Wu Shuwen <mikewushuwen@outlook.com> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit d953184) Signed-off-by: Cheng Pan <chengpan@apache.org>
Fixes #7590.
Why are the changes needed?
When SparkContext stops before engine shutdown reaches
stopServer(), the latch inSparkSQLEngine.mainmay never be released. The main thread polls the latch and checks SparkContext; if it is stopped first, the code now throwsKyuubiExceptionthrough the existing engine error path. That path records the abnormal termination and diagnostics instead of returning normally (which could make YARN report the application as succeeded). Earlier PRs #7592 and #7680 are closed and unmerged.How was this patch tested?
git diff --checkpassed for this review follow-up.SparkSQLEngineSuiterun was on commite24adad, before this follow-up, and does not validate the current diff.Was this patch assisted by generative AI tooling?
Assisted-by: Pi worker dev-w11@stew-c1-4w (openai-codex/gpt-6-luna).